Kuo['apijson/admin_permission'] = {
    url: plug + "apijson" + FENGE + "admin_permission" + FENGE,
    YESNO: ["否", "是"],
    OFF: ["删除", "关闭", "开启"],
    $grade: { "-1": "游客", "0": "普通用户", "88": "超级管理" },
    TYPE: ["静态资源", "Node.js", "PHP"],
    init: function () {
        Kuo['apijson/admin_permission'].get();
        var xxx = '<option value="">全部状态</option>';
        for (var n in Kuo["apijson/admin_permission"].OFF) {
            xxx += '<option value="' + n + '">' + Kuo["apijson/admin_permission"].OFF[n] + '</option>';
        }
        $("." + $class + "saixuan [name='so_off']").html(xxx);
        layui.form.render("select");
    },
    edit(OBJ, diercai) {
        if (diercai != "add") {
            diercai = "put";
            var title = "编辑权限";
        } else {
            var title = "新建权限";
        }
        window.UIMUI = Array();
        var D = OBJ.data;
        var BIAO = [];
        var caifuw = function (data) {
            let zifuchuan = [];
            try {
                zifuchuan = JSON.parse(data);
            } catch (error) {

            }
            return zifuchuan.join(',');
        }
        var html = '<form name="form" id="form" class="layui-form ' + $class + '">';
        BIAO = [

            'id($$)id($$)hidden($$)($$)id($$)' + D.id,
            'tags($$)tag名称($$)text($$)($$)外部调用tag名称($$)' + D.tags,
            'name($$)表名($$)text($$)($$)对应表名可为空($$)' + D.name,
            'get($$)Get($$)checkbox($$)($$)Kuo["apijson/admin_permission"].$grade($$)' + caifuw(D.get),
            'put($$)Put($$)checkbox($$)($$)Kuo["apijson/admin_permission"].$grade($$)' + caifuw(D.put),
            'add($$)Add($$)checkbox($$)($$)Kuo["apijson/admin_permission"].$grade($$)' + caifuw(D.add),
            'del($$)Del($$)checkbox($$)($$)Kuo["apijson/admin_permission"].$grade($$)' + caifuw(D.del),
            'data($$)Data($$)checkbox($$)($$)Kuo["apijson/admin_permission"].$grade($$)' + caifuw(D.data),

            'atime($$)更改时间($$)time($$)($$)更改时间($$)' + D.atime,
            'off($$)开关($$)select($$)($$)Kuo["apijson/admin_permission"].OFF($$)' + D.off,
            'detail($$)详细说明($$)textarea($$)($$)详细说明($$)' + D.detail
        ];

        let Dprohibit = {};
        try {
            Dprohibit = JSON.parse(D.prohibit);
        } catch (error) {

        }
        let grade = Kuo["apijson/admin_permission"].$grade;
        let mid = "All";
        BIAO.push([
            'grade_' + mid + '',
            '<span style="color:red;">所有角色</span><br/>禁用字段',
            "caidan",
            'width:88px;',
            '禁用字段名',
            Dprohibit[mid] ? Dprohibit[mid] : []
        ]);

        for (let mid in grade) {

            BIAO.push([
                'grade_' + mid + '',
                grade[mid] + '<br>禁用字段',
                "caidan",
                'width:88px;',
                '禁用字段名',
                Dprohibit[mid] ? Dprohibit[mid] : []
            ]);

        }


        for (var z in BIAO) {
            html += jsfrom(BIAO[z]);
        }

        html += jsfrom('ff' + $class + '($$)($$)submit($$)($$)layer.close(OPID);Kuo[\'apijson/admin_permission\'].init()($$)提交($$)tijiao');
        html += "</form>";
        OPID = layer.open({
            type: 1,
            zIndex: 10000,
            title: title,
            area: ['100%', '100%'],
            fixed: true,
            maxmin: true,
            content: html,
            success: function (layero, index) {
            }
        });

        layui.form.on('submit(ff' + $class + ')', function (formdata) {
            formdata = formdata.field;
            formdata.Format = 'json';


            apptongxin(Kuo['apijson/admin_permission'].url + TOKEN + FENGE + diercai, formdata, function (data) {
                if (data.token && data.token != "") {
                    TOKEN = data.token;
                }
                if (data.code == 99) {
                    layer.close(OPID);
                    layer.msg("请登陆", {
                        offset: 'c',
                        time: 2000
                    }, function () {
                        loadjs("home");
                    });
                } else if (data.code == 1) {

                    if (diercai == "put") {
                        OBJ.update(data.data);
                        layer.close(OPID);
                    } else {
                        Kuo['apijson/admin_permission'].get();
                        layer.close(OPID);
                    }

                } else {

                    layer.msg(data.msg, {
                        zIndex: 99999,
                        offset: 'c',
                        time: 2000
                    });
                }
            });
            return false;
        });

        layui.form.render();

    }, del(OBJ) {
        var fromdata = {
            Format: 'json',
            id: OBJ.data.id
        };
        apptongxin(Kuo['apijson/admin_permission'].url + TOKEN + FENGE + 'del', fromdata, function (data) {
            if (data.token && data.token != "") {
                TOKEN = data.token;
            }
            if (data.code == 99) {
                layer.msg("请登陆", {
                    offset: 'c',
                    time: 2000
                }, function () {
                    loadjs("home");
                });
            } else if (data.code == 1) {
                OBJ.del();
            } else {
                layer.msg(data.msg, {
                    zIndex: 99999,
                    offset: 'c',
                    time: 2000
                });
            }
        });

    }, CHUUSER(data) {

        let htmls = "";
        let zuhes = [];
        try {
            zuhes = JSON.parse(data);
        } catch (error) { }
        if (zuhes) {
            for (let mx in zuhes) {
                let mx_ = zuhes[mx];
                htmls += '' + Kuo['apijson/admin_permission'].$grade[mx_] + '<br/>';
            }
        }
        return htmls;


    },
    add() {
        Kuo['apijson/admin_permission'].edit(
            {
                data:
                    { "id": 0, "tags": "", "name": "", "get": "[]", "put": "[]", "add": "[]", "del": "[]", "data": "[]", "detail": "", "atime": "0", "off": "2", "prohibit": "{}" }
            },
            'add');

    },
    get() {

        $("#LAY_app_body ." + $class).html('<style> .' + $class + ' .qfys0{color:#FF5722;} .' + $class + ' .qfys1{color:#009688;}.' + $class + ' .qfys2{color:green;}.' + $class + ' .qfys3{color:#1E9FFF;}</style><div class="layui-fluid"><div class="layui-card"><div class="layui-card-body" style="padding: 15px;">'
            +
            '<div class="' + $class + 'saixuan" style="display:none;margin-bottom:8px;"><form name="form" class="layui-form"><div class="layui-inline" style="width:108px;"> <select name="so_off" class="so_var"></select> </div>   <div class="layui-inline" style="width:128px;"> <input class="layui-input so_var" name="so_name" autocomplete="off" placeholder="表名"> </div>    <div class="layui-inline" style="width:128px;"> <input class="layui-input so_var" name="so_tags" autocomplete="off" placeholder="Tags"> </div>    <button class="layui-btn" lay-event="sousuo" lay-submit lay-filter="tijiao' + $class + '">搜索</button></form> </div>'
            +
            '<table class="layui-hide" id="apijson' + $class + '" lay-filter="apijson' + $class + '"></table></div></div></div>');
        layui.table.render({
            elem: '#apijson' + $class,
            url: Kuo['apijson/admin_permission'].url + TOKEN + FENGE + 'get',
            toolbar: '<div><a class="layui-btn layui-btn-normal" lay-event="add"><i class="layui-icon layui-icon-addition"></i>新增</a> <a class="layui-btn " lay-event="refresh"><i class="layui-icon layui-icon-refresh-3"></i> 刷新</a> <a class="layui-btn layui-btn-danger" lay-event="saixuan"><i class="layui-icon layui-icon-search"></i>筛选</a> </div>',
            cols: [
                [{
                    field: 'id',
                    title: 'ID',
                    width: 88,
                }, {
                    field: "name",
                    width: 158,
                    title: "对应表名"

                }, {
                    field: "tags",
                    title: "Tags名字"

                }, {
                    field: "get",
                    title: "Get允许",
                    templet: function (d) {
                        return Kuo['apijson/admin_permission'].CHUUSER(d.get);
                    }

                }, {
                    field: "put",
                    title: "Put允许",
                    templet: function (d) {
                        return Kuo['apijson/admin_permission'].CHUUSER(d.put);
                    }
                }, {
                    field: "off",
                    title: "状态",
                    width: 108,
                    templet: function (d) {
                        return Kuo['apijson/admin_permission'].OFF[d.off];
                    }
                }, {
                    field: "atime",
                    title: "时间",
                    width: 188,
                    templet: function (d) {

                        return time(d.atime);
                    }
                }, {


                    title: '操作',
                    width: 158,
                    templet: function (d) {
                        return '<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
                    }
                }]
            ],
            limit: 20,
            page: true,
            done: function (data, curr, count) {
                if (data.token && data.token != "") {
                    TOKEN = data.token;
                }


                if (data.$OFF) {
                    Kuo['apijson/admin_permission'].OFF = data.$OFF;
                }

                if (data.$grade) {

                    let $grade = {};
                    for (let m in data.$grade) {
                        let data_ = data.$grade[m];
                        let jixi = data_.split('@');
                        $grade[parseInt(jixi[0])] = jixi[1].trim();
                    }
                    Kuo['apijson/admin_permission'].$grade = $grade;
                }


            }
        });
        layui.table.on('toolbar(apijson' + $class + ')', function (obj) {
            if (obj.event === 'add') {
                Kuo['apijson/admin_permission'].add();
            } else if (obj.event === 'refresh') {
                layer.closeAll();
                Kuo['apijson/admin_permission'].init();
            } else if (obj.event === 'saixuan') {
                $("." + $class + "saixuan").toggle();
            }
        });

        layui.table.on('tool(apijson' + $class + ')', function (obj) {
            if (obj.event === 'del') {
                layer.confirm('真的要删除吗?', function (index) {
                    Kuo['apijson/admin_permission'].del(obj);
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                Kuo['apijson/admin_permission'].edit(obj);
            }

        });

        layui.form.on('submit(tijiao' + $class + ')', function (formdata) {
            formdata = formdata.field;
            var zuhesou = {};
            $('.' + $class + 'saixuan .so_var').each(function (i, v) {
                if ($(v).val() != "") {
                    zuhesou[$(v).attr('name').replace('so_', '')] = $(v).val();
                }
            });
            layui.table.reload('apijson' + $class, {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                url: Kuo['apijson/admin_permission'].url + TOKEN + FENGE + 'get',
                where: zuhesou
            });
            return false;
        });

        layui.table.render();
    }
}
Kuo['apijson/admin_permission'].init();